<template>
  <div style="width: 100%; height: 100%">
    <div class="container" v-show="!no_data_show">
      <h4>分拣进度</h4>
      <h3>{{ new_order_list.over_count_percent }}%</h3>
      <div class="percent_box">
        <div
          class="is_sort"
          :style="[
            { flex: new_order_list.over_count_percent || 1 },
            {
              borderRadius: new_order_list.no_count_percent == 0 ? '8px' : '',
            },
          ]"
          v-show="new_order_list.over_count_percent != 0"
        >
          <div>
            {{ new_order_list.over_count }}({{
              new_order_list.over_count_percent
            }}%)
          </div>
          <div>已分拣</div>
        </div>
        <div
          class="no_sort"
          :style="[
            { flex: new_order_list.no_count_percent || 1 },
            {
              borderRadius: new_order_list.over_count_percent == 0 ? '8px' : '',
            },
          ]"
          v-show="new_order_list.no_count_percent != 0"
        >
          <div>
            {{ new_order_list.no_count }}({{
              new_order_list.no_count_percent
            }}%)
          </div>
          <div>未分拣</div>
        </div>
      </div>
    </div>
    <div class="no_data" v-show="no_data_show">
      <img src="@/assets/images/no_data.png" alt="" />
    </div>
  </div>
</template>
<script>
export default {
  props: {
    order_list: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      new_order_list: {
        count: 0,
        over_count: 0,
        over_count_percent: 0,
        no_count: 0,
        no_count_percent: 0,
      },
      no_data_show: true,
    };
  },
  watch: {
    order_list: {
      handler(val) {
        this.new_order_list.count = val.count;
        this.new_order_list.over_count = val.over_count;
        this.new_order_list.no_count = val.count - val.over_count;
        this.new_order_list.over_count_percent = this.order_list_over(val);
        this.new_order_list.no_count_percent = this.order_list_no(val);
        if (val.count == 0) {
          this.no_data_show = true;
        } else {
          this.no_data_show = false;
        }
      },
      deep: true,
    },
  },
  methods: {
    order_list_over(val) {
      let { count, over_count } = val;
      // 已分拣
      let percent = 0;
      if (count == 0) {
        percent = 0;
      } else {
        percent = (over_count / count) * 100;
      }
      percent = Math.round(percent);
      return percent;
    },
    order_list_no(val) {
      let { count, over_count } = val;
      // 未分拣
      let percent = 0;
      if (count == 0) {
        percent = 0;
      } else {
        let no = count - over_count;
        percent = (no / count) * 100;
      }
      percent = Math.round(percent);
      return percent;
    },
  },
};
</script>
<style lang='scss' scoped>
.container {
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 20px 40px;
  display: flex;
  align-items: center;
  flex-direction: column;

  h3 {
    color: #f65754;
    font-weight: 700;
    padding-top: 20px;
    font-size: 28px;
  }
  h4 {
    color: #f65754;
    padding-top: 35px;
    font-size: 20px;
  }
  .percent_box {
    width: 100%;
    height: 50px;
    margin-top: 35px;

    display: flex;
    align-items: center;
    .is_sort,
    .no_sort {
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      font-size: 14px;
      padding: 0 2px;
      div {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      div:last-child {
        font-size: 10px !important;
        padding-top: 4px;
      }
    }
    .is_sort {
      background-color: #f85556;
      color: #fff;
      box-shadow: 0px 0px 8px #f85556;
      border-radius: 8px 0 0 8px;
    }
    .no_sort {
      background-color: #e6e6e6;
      color: #999;
      border-radius: 0 8px 8px 0;
    }
  }
}
.no_data {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  img {
    transform: translateY(-8px);
  }
}
</style>
